home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / oop.swg / 0026_Efficient Turbo Vision.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  3KB  |  98 lines

  1. {
  2. From: BRIAN RICHARDSON
  3. Subj: Efficient Tv2
  4. ---------------------------------------------------------------------------
  5.  On 10-08-93 FRANK DERKS wrote to ALL...
  6.  
  7.   Hello All,
  8.  
  9.   for those who have read my other message (Efficient TV, Thu 07). Maybe
  10.   some of you can expand on the following idea. How do I create a
  11.   'dynamic' pick list box: a box that is displayed only when I have
  12.  
  13.   Or maybe more simple : what I'm after is a sort of inputline-object
  14.   which can be cycled through a number of predefined values. }
  15.  
  16. uses objects, app, dialogs, drivers;
  17.  
  18. type
  19.    PRoomInputLine = ^TRoomInputLine;
  20.    TRoomInputLine = object(TInputLine)
  21.      StatusList : PStringCollection;
  22.      Index      : integer;
  23.  
  24.      constructor Init(var Bounds: TRect; AMaxLen: integer;
  25.                       AStatusList : PStringCollection);
  26.      procedure HandleEvent(var Event : TEvent); virtual;
  27.      procedure Up; virtual;
  28.      procedure Down; virtual;
  29.    end;
  30.  
  31.    PRoomDialog = ^TRoomDialog;
  32.    TRoomDialog = object(TDialog)
  33.       constructor Init(List : PStringCollection);
  34.    end;
  35.  
  36. constructor TRoomInputLine.Init(var Bounds : TRect; AMaxLen: Integer;
  37.                               AStatusList : PStringCollection);
  38. begin
  39.    inherited Init(Bounds, AMaxLen);
  40.    StatusList := AStatusList;
  41.    Index := 0;
  42.    SetData(PString(StatusList^.At(Index))^);
  43. end;
  44.  
  45. procedure TRoomInputLine.Up;
  46. begin
  47.    Index := (Index + 1) Mod StatusList^.Count;
  48.    SetData(PString(StatusList^.At(Index))^);
  49. end;
  50.  
  51.  
  52. procedure TRoomInputLine.Down;
  53. begin
  54.    if Index = 0 then Index := (StatusList^.Count - 1) else
  55.    Dec(Index);
  56.    SetData(PString(StatusList^.At(Index))^);
  57. end;
  58.  
  59. procedure TRoomInputLine.HandleEvent(var Event: TEvent);
  60. begin
  61.    if (Event.What = evKeyDown) then begin
  62.       case Event.KeyCode of
  63.          kbUp     : Up;
  64.          kbDown   : Down;
  65.       else
  66.       inherited HandleEvent(Event);
  67.       end; end else
  68.    inherited HandleEvent(Event);
  69. end;
  70.  
  71. constructor TRoomDialog.Init(List : PStringCollection);
  72. var R: TRect;
  73. begin
  74.    R.Assign(20, 5, 60, 20);
  75.    inherited Init(R, '');
  76.    R.Assign(15, 7, 25, 8);
  77.    Insert(New(PRoomInputLine, Init(R, 20, List)));
  78.    R.Assign(15, 9, 25, 10);
  79.    Insert(New(PRoomInputLine, Init(R, 20, List)));
  80.  
  81. end;
  82.  
  83. var
  84.    RoomApp  : TApplication;
  85.    List     : PStringCollection;
  86. begin
  87.    RoomApp.Init;
  88.    List := New(PStringCollection, Init(3, 1));
  89.    with List^ do begin
  90.       Insert(NewStr('Vacant')); Insert(NewStr('Occupied'));
  91.       Insert(NewStr('Cleaning'));
  92.    end;
  93.    Application^.ExecuteDialog(New(PRoomDialog, Init(List)), nil);
  94.    Dispose(List, Done);
  95.    RoomApp.Done;
  96. end.
  97.  
  98.